home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / misc / bgui12.lha / demos / WallStreet / WallStreet.c < prev    next >
C/C++ Source or Header  |  1995-06-21  |  17KB  |  730 lines

  1. /*
  2.  *    WALLSTREET.C
  3.  *
  4.  *    (C) Copyright 1995 Jaba Development.
  5.  *    (C) Copyright 1995 Jan van den Baard.
  6.  *        All Rights Reserved.
  7.  *
  8.  *    The 1000000th commodities Exchange clone :)
  9.  */
  10.  
  11. #include "WallStreet.h"
  12.  
  13. /*
  14.  *    Main module data.
  15.  */
  16. static Object *WO_WallStreet, *GO_Brokers, *GO_Show, *GO_HideB, *GO_Active, *GO_Remove;
  17. static Object *GO_Hide, *GO_Quit, *CO_WallStreet;
  18.  
  19. static struct Window     *WallStreet;
  20. static ULONG          WallStreetSig, BrokerSig;
  21. static ULONG          BuildCount;
  22. static struct ListBroker *LastSelected;
  23. static struct ReadArgs     *ShellArgs;
  24. static struct Args      Args;
  25. static UBYTE        **TTypes;
  26. static UBYTE         *Pubscreen;
  27. struct Library         *BGUIBase;
  28.  
  29. /*
  30.  *    Some menus.
  31.  */
  32. static struct NewMenu WallStreetMenus[] = {
  33.     Title( "Project" ),
  34.         Item( "About...",       "?",    ID_ABOUT ),
  35.         ItemBar,
  36.         Item( "Hide",           "H",    ID_HIDE  ),
  37.         Item( "Quit",           "Q",    ID_QUIT  ),
  38.     End
  39. };
  40.  
  41. /*
  42.  *    Show a BGUI requester. Used for
  43.  *    general information.
  44.  */
  45. static ULONG Report( UBYTE *gads, UBYTE *string, ... )
  46. {
  47.     struct bguiRequest    req = { NULL };
  48.  
  49.     req.br_GadgetFormat    = gads;
  50.     req.br_TextFormat    = string;
  51.     req.br_Underscore    = '_';
  52.     req.br_Flags        = WallStreet ? BREQF_CENTERWINDOW|BREQF_AUTO_ASPECT|BREQF_LOCKWINDOW : BREQF_CENTERWINDOW|BREQF_AUTO_ASPECT;
  53.  
  54.     return( BGUI_RequestA( WallStreet, &req, ( ULONG * )( &string + 1 )));
  55. }
  56.  
  57. /*
  58.  *    Listview resource-hook. This builds the "ListBroker"
  59.  *    structures from the "BrokerCopy" structures.
  60.  */
  61. static SAVEDS ASM APTR ListResourceFunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct lvResource *lvr )
  62. {
  63.     struct ListBroker        *lb;
  64.     struct BrokerCopy        *bc;
  65.     APTR                 rc = 0L;
  66.  
  67.     switch ( lvr->lvr_Command ) {
  68.  
  69.         case    LVRC_MAKE:
  70.             /*
  71.              *    Here we construct a ListBroker structure
  72.              *    from the input BrokerCopy structure.
  73.              */
  74.             bc = ( struct BrokerCopy * )lvr->lvr_Entry;
  75.             if ( lb = ( struct ListBroker * )AllocVec( sizeof( struct ListBroker ), MEMF_PUBLIC )) {
  76.                 /*
  77.                  *    Setup the pre-parse string so that we
  78.                  *    can display active brokers in HIGHLIGHTEXTPEN
  79.                  *    and inactive brokers in TEXTPEN.
  80.                  */
  81.                 lb->lb_PreParse[ 0 ] = '\33';
  82.                 lb->lb_PreParse[ 1 ] = 'd';
  83.                 /*
  84.                  *    Copy name, title and description.
  85.                  */
  86.                 strcpy( &lb->lb_Name[ 0 ], &bc->bc_Name[ 0 ] );
  87.                 strcpy( &lb->lb_Title[ 0 ], &bc->bc_Title[ 0 ] );
  88.                 strcpy( &lb->lb_Descr[ 0 ], &bc->bc_Descr[ 0 ] );
  89.                 /*
  90.                  *    And also the task and flags.
  91.                  */
  92.                 lb->lb_Task      = bc->bc_Task;
  93.                 lb->lb_Flags      = bc->bc_Flags;
  94.                 /*
  95.                  *    Setup current build counter.
  96.                  */
  97.                 lb->lb_BuildCount = BuildCount;
  98.                 rc = ( APTR )lb;
  99.             }
  100.             break;
  101.  
  102.         case    LVRC_KILL:
  103.             /*
  104.              *    Simply de-allocate the ListBroker
  105.              *    structure as created above.
  106.              */
  107.             FreeVec( lvr->lvr_Entry );
  108.             break;
  109.     }
  110.     return( rc );
  111. }
  112.  
  113. /*
  114.  *    Listiew rendering hook. Simply
  115.  *    returns the name of the broker
  116.  *    prepended by a Info text command
  117.  *    sequence to determine the color.
  118.  */
  119. static SAVEDS ASM UBYTE *ListRenderFunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct lvRender *lvr )
  120. {
  121.     struct ListBroker        *lb = ( struct ListBroker * )lvr->lvr_Entry;
  122.  
  123.     /*
  124.      *    Active brokers are rendered in highlight text pen
  125.      *    and non-activated brokers in normal text pen.
  126.      */
  127.     lb->lb_PreParse[ 2 ] = (( lb->lb_Flags & COF_ACTIVE ) ? HIGHLIGHTTEXTPEN : TEXTPEN ) + 48;
  128.  
  129.     return( &(( struct ListBroker * )lvr->lvr_Entry )->lb_PreParse[ 0 ] );
  130. }
  131.  
  132. /*
  133.  *    The hook structures for the listview.
  134.  */
  135. static struct Hook ListResource = { NULL, NULL, ( HOOKFUNC )ListResourceFunc, NULL, NULL };
  136. static struct Hook ListRender    = { NULL, NULL, ( HOOKFUNC )ListRenderFunc,   NULL, NULL };
  137.  
  138. /*
  139.  *    Find the broker entry by referencing
  140.  *    it's task address.
  141.  */
  142. static struct ListBroker *FindListBroker( LONG task )
  143. {
  144.     struct ListBroker    *lb = NULL;
  145.  
  146.     /*
  147.      *    Get the first broker from the list.
  148.      */
  149.     if ( lb = ( struct ListBroker * )FirstEntry( GO_Brokers )) {
  150.         do {
  151.             /*
  152.              *    Is this the one we are
  153.              *    looking for?
  154.              */
  155.             if ( lb->lb_Task == task ) {
  156.                 /*
  157.                  *    Yes. Update the build counter
  158.                  *    and stop looking.
  159.                  */
  160.                 lb->lb_BuildCount = BuildCount;
  161.                 break;
  162.             }
  163.             /*
  164.              *    Next please...
  165.              */
  166.             lb = ( struct ListBroker * )NextEntry( GO_Brokers, lb );
  167.         } while ( lb );
  168.     }
  169.     return( lb );
  170. }
  171.  
  172. /*
  173.  *    Recreate the broker list. Please note that this
  174.  *    is not very pretty code.
  175.  *
  176.  *    It runs down the broker list replacing/adding
  177.  *    entries and when that is done it runs down the
  178.  *    listed brokers to remove the obsolete entries.
  179.  *
  180.  *    All in all much work.
  181.  */
  182. static VOID BuildBrokerList( void )
  183. {
  184.     struct Node        *node;
  185.     struct ListBroker    *inlist, *rem = NULL;
  186.     struct List         list;
  187.  
  188.     /*
  189.      *    Increase build counter.
  190.      */
  191.     BuildCount++;
  192.  
  193.     /*
  194.      *    Initialize and setup the
  195.      *    broker list.
  196.      */
  197.     NewList( &list );
  198.     CopyBrokerList( &list );
  199.  
  200.     /*
  201.      *    Browse through the new list.
  202.      */
  203.     for ( node = list.lh_Head; node->ln_Succ; node = node->ln_Succ ) {
  204.         /*
  205.          *    Was this one in the list already?
  206.          */
  207.         if ( inlist = FindListBroker( (( struct BrokerCopy *)node )->bc_Task )) {
  208.             /*
  209.              *    Yes. Update the data from this
  210.              *    broker.
  211.              */
  212.             rem = ( struct ListBroker * )ReplaceEntry( WallStreet, GO_Brokers, inlist, node );
  213.             /*
  214.              *    Was it the last selected one? If so set it
  215.              *    to the replaced entry to keep double-clicks
  216.              *    working.
  217.              */
  218.             if ( inlist == LastSelected )
  219.                 LastSelected = rem;
  220.         } else
  221.             /*
  222.              *    Not available yet. Add it to the
  223.              *    list.
  224.              */
  225.             AddEntry( WallStreet, GO_Brokers, node, LVAP_TAIL );
  226.     }
  227.  
  228.     /*
  229.      *    Free the system broker list.
  230.      */
  231.     FreeBrokerList( &list );
  232.  
  233.     /*
  234.      *    This needs to be NULL incase there
  235.      *    are no entries to remove.
  236.      */
  237.     rem = NULL;
  238.  
  239.     /*
  240.      *    All brokers which have a build counter
  241.      *    different from the current counter are
  242.      *    not running anymore so we remove them
  243.      *    here.
  244.      */
  245.     if ( inlist = ( struct ListBroker * )FirstEntry( GO_Brokers )) {
  246.         do {
  247.             /*
  248.              *    Different counter value?
  249.              */
  250.             if ( inlist->lb_BuildCount != BuildCount ) {
  251.                 /*
  252.                  *    Yes. Remove it.
  253.                  */
  254.                 rem    = inlist;
  255.                 inlist = ( struct ListBroker * )NextEntry( GO_Brokers, inlist );
  256.                 RemoveEntry( GO_Brokers, rem );
  257.             } else
  258.                 /*
  259.                  *    Next please.
  260.                  */
  261.                 inlist = ( struct ListBroker * )NextEntry( GO_Brokers, inlist );
  262.         } while ( inlist );
  263.         /*
  264.          *    Visual update when there were brokers
  265.          *    are removed.
  266.          */
  267.         if ( rem )
  268.             RefreshList( WallStreet, GO_Brokers );
  269.     }
  270. }
  271.  
  272. /*
  273.  *    Send a command to all selected brokers.
  274.  */
  275. static VOID SendCxCmd( ULONG command )
  276. {
  277.     struct ListBroker        *lb;
  278.  
  279.     /*
  280.      *    Get the first selected broker.
  281.      */
  282.     if ( lb = ( struct ListBroker * )FirstSelected( GO_Brokers )) {
  283.         /*
  284.          *    Get 'm all.
  285.          */
  286.         do {
  287.             /*
  288.              *    Send the command to the broker. Don't you
  289.              *    just love undocumented OS features ;)
  290.              */
  291.             BrokerCommand( &lb->lb_Name[ 0 ], command );
  292.             /*
  293.              *    Get the next broker.
  294.              */
  295.             lb = ( struct ListBroker * )NextSelected( GO_Brokers, lb );
  296.         } while ( lb );
  297.     }
  298. }
  299.  
  300. /*
  301.  *    Build the WallStreet window.
  302.  */
  303. static VOID OpenWallStreetWindow( void )
  304. {
  305.     /*
  306.      *    Object created already?
  307.      */
  308.     if ( ! WO_WallStreet ) {
  309.         /*
  310.          *    No. Create it.
  311.          */
  312.         WO_WallStreet = WindowObject,
  313.             WINDOW_Title,            VERS " (" DATE ")",
  314.             WINDOW_AutoAspect,        TRUE,
  315.             WINDOW_SmartRefresh,        TRUE,
  316.             WINDOW_MenuStrip,        WallStreetMenus,
  317.             WINDOW_PubScreenName,        Pubscreen,
  318.             WINDOW_ScaleWidth,        15,
  319.             WINDOW_ScaleHeight,        15,
  320.             WINDOW_MasterGroup,
  321.                 VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  322.                     StartMember,
  323.                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  324.                             FRM_Type,        FRTYPE_BUTTON,
  325.                             FRM_Recessed,        TRUE,
  326.                             StartMember,
  327.                                 GO_Brokers = ListviewObject,
  328.                                     LISTV_MultiSelect,        TRUE,
  329.                                     LISTV_MultiSelectNoShift,    TRUE,
  330.                                     LISTV_ResourceHook,        &ListResource,
  331.                                     LISTV_DisplayHook,        &ListRender,
  332.                                     GA_ID,                ID_BROKERLIST,
  333.                                 EndObject,
  334.                             EndMember,
  335.                             StartMember,
  336.                                 HGroupObject, Spacing( 4 ), GROUP_EqualWidth, TRUE,
  337.                                     StartMember, GO_Show  = KeyButton( "_Show", ID_SHOW        ), EndMember,
  338.                                     StartMember, GO_HideB = KeyButton( "Hi_de", ID_HIDEBROKERS ), EndMember,
  339.                                 EndObject, FixMinHeight,
  340.                             EndMember,
  341.                             StartMember,
  342.                                 HGroupObject, Spacing( 4 ), GROUP_EqualWidth, TRUE,
  343.                                     StartMember, GO_Active = KeyButton( "_Flip Status", ID_ACTIVE ), EndMember,
  344.                                     StartMember, GO_Remove = KeyButton( "_Remove",      ID_REMOVE ), EndMember,
  345.                                 EndObject, FixMinHeight,
  346.                             EndMember,
  347.                         EndObject,
  348.                     EndMember,
  349.                     StartMember,
  350.                         HGroupObject, Spacing( 4 ),
  351.                             StartMember, GO_Hide = KeyButton( "_Hide", ID_HIDE ), EndMember,
  352.                             VarSpace( DEFAULT_WEIGHT ),
  353.                             StartMember, GO_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
  354.                         EndObject, FixMinHeight,
  355.                     EndMember,
  356.                 EndObject,
  357.         EndObject;
  358.  
  359.         if ( WO_WallStreet ) {
  360.             /*
  361.              *    Attach gadget keys. Although, strictly
  362.              *    speaking I should, I do no error
  363.              *    checking here...
  364.              */
  365.             GadgetKey( WO_WallStreet, GO_Show,    "s" );
  366.             GadgetKey( WO_WallStreet, GO_HideB,    "d" );
  367.             GadgetKey( WO_WallStreet, GO_Active,    "f" );
  368.             GadgetKey( WO_WallStreet, GO_Remove,    "r" );
  369.             GadgetKey( WO_WallStreet, GO_Hide,    "h" );
  370.             GadgetKey( WO_WallStreet, GO_Quit,    "q" );
  371.         }
  372.     }
  373.  
  374.     /*
  375.      *    Object OK?
  376.      */
  377.     if ( WO_WallStreet ) {
  378.         /*
  379.          *    Create/Update the broker list.
  380.          */
  381.         BuildBrokerList();
  382.         /*
  383.          *    Pop the window.
  384.          */
  385.         if ( WallStreet = WindowOpen( WO_WallStreet ))
  386.             /*
  387.              *    Get window signal mask.
  388.              */
  389.             GetAttr( WINDOW_SigMask, WO_WallStreet, &WallStreetSig );
  390.     }
  391. }
  392.  
  393. /*
  394.  *    Close the WallStreet window.
  395.  */
  396. static VOID CloseWallStreetWindow( void )
  397. {
  398.     /*
  399.      *    Close the window and nuke the
  400.      *    pointer and signal mask.
  401.      */
  402.     WindowClose( WO_WallStreet );
  403.     WallStreet    = NULL;
  404.     WallStreetSig = 0L;
  405. }
  406.  
  407. /*
  408.  *    Handle all incoming message traffic.
  409.  */
  410. static VOID EventHandler( void )
  411. {
  412.     BOOL             running = TRUE;
  413.     ULONG             sigrec, rc, type, id, ds[ 2 ], dm[ 2 ];
  414.     struct ListBroker    *lb;
  415.  
  416.     do {
  417.         /*
  418.          *    Wait for a signal...
  419.          */
  420.         sigrec = Wait( WallStreetSig | BrokerSig );
  421.  
  422.         /*
  423.          *    A window signal?
  424.          */
  425.         if ( sigrec & WallStreetSig ) {
  426.             /*
  427.              *    Get the messages.
  428.              */
  429.             while ( WallStreet && (( rc = HandleEvent( WO_WallStreet )) != WMHI_NOMORE )) {
  430.                 switch ( rc ) {
  431.  
  432.                     case    WMHI_CLOSEWINDOW:
  433.                     case    ID_HIDE:
  434.                         /*
  435.                          *    Close the window.
  436.                          */
  437.                         if ( WallStreet )
  438.                             CloseWallStreetWindow();
  439.                         break;
  440.  
  441.                     case    ID_ABOUT:
  442.                         /*
  443.                          *    Show'm the info.
  444.                          */
  445.                         Report( "_Continue", ISEQ_C ISEQ_HIGHLIGHT VERS " (" DATE ")\n\n" ISEQ_TEXT
  446.                                      "(C) Copyright 1995 Jaba Development\n"
  447.                                      "Written by Jan van den Baard" );
  448.                         break;
  449.  
  450.                     case    ID_QUIT:
  451.                         /*
  452.                          *    Bye now.
  453.                          */
  454.                         running = FALSE;
  455.                         break;
  456.  
  457.                     case    ID_SHOW:
  458.                         /*
  459.                          *    Show selected brokers.
  460.                          */
  461.                         SendCxCmd( CXCMD_APPEAR );
  462.                         break;
  463.  
  464.                     case    ID_HIDEBROKERS:
  465.                         /*
  466.                          *    Hide selected brokers.
  467.                          */
  468.                         SendCxCmd( CXCMD_DISAPPEAR );
  469.                         break;
  470.  
  471.                     case    ID_ACTIVE:
  472.                         /*
  473.                          *    Flip activity status of the selected brokers.
  474.                          */
  475.                         if ( lb = ( struct ListBroker * )FirstSelected( GO_Brokers )) {
  476.                             do {
  477.                                 BrokerCommand( &lb->lb_Name[ 0 ], lb->lb_Flags & COF_ACTIVE ? CXCMD_DISABLE : CXCMD_ENABLE );
  478.                                 lb = ( struct ListBroker * )NextSelected( GO_Brokers, lb );
  479.                             } while ( lb );
  480.                         }
  481.                         break;
  482.  
  483.                     case    ID_BROKERLIST:
  484.                         /*
  485.                          *    Get the last selected entry.
  486.                          */
  487.                         GetAttr( LISTV_LastClicked, GO_Brokers, ( ULONG * )&lb );
  488.                         /*
  489.                          *    The same one as the previous selection?
  490.                          */
  491.                         if ( lb == LastSelected ) {
  492.                             /*
  493.                              *    Time it.
  494.                              */
  495.                             CurrentTime( &ds[ 1 ], &dm[ 1 ] );
  496.                             /*
  497.                              *    Double clicked?
  498.                              */
  499.                             if ( DoubleClick( ds[ 0 ], dm[ 0 ], ds[ 1 ], dm[ 1 ] ))
  500.                                 /*
  501.                                  *    Yes. Show it's information.
  502.                                  */
  503.                                 Report( "_OK", ISEQ_C "%s\n%s", &lb->lb_Title[ 0 ], &lb->lb_Descr[ 0 ] );
  504.                         }
  505.                         /*
  506.                          *    Setup this selection.
  507.                          */
  508.                         LastSelected = lb;
  509.                         /*
  510.                          *    Time it.
  511.                          */
  512.                         CurrentTime( &ds[ 0 ], &dm[ 0 ] );
  513.                         break;
  514.  
  515.                     case    ID_REMOVE:
  516.                         /*
  517.                          *    Remove all selected brokers.
  518.                          */
  519.                         SendCxCmd( CXCMD_KILL );
  520.                         break;
  521.                 }
  522.             }
  523.         }
  524.  
  525.         /*
  526.          *    Commodity signal?
  527.          */
  528.         if ( sigrec & BrokerSig ) {
  529.             /*
  530.              *    Get messages from the broker.
  531.              */
  532.             while ( MsgInfo( CO_WallStreet, &type, &id, NULL ) != CMMI_NOMORE ) {
  533.                 /*
  534.                  *    Evaluate message.
  535.                  */
  536.                 switch ( type ) {
  537.  
  538.                     case    CXM_IEVENT:
  539.                         switch ( id ) {
  540.                             case    CXK_SHOW:
  541.                                 /*
  542.                                  *    Popup the window.
  543.                                  */
  544.                                 if ( ! WallStreet )
  545.                                     OpenWallStreetWindow();
  546.                                 break;
  547.                         }
  548.                         break;
  549.  
  550.                     case    CXM_COMMAND:
  551.                         switch ( id ) {
  552.                                 case    CXCMD_KILL:
  553.                                     /*
  554.                                      *    Bye bye.
  555.                                      */
  556.                                     running = FALSE;
  557.                                     break;
  558.  
  559.                                 case    CXCMD_DISABLE:
  560.                                     /*
  561.                                      *    Disable the broker.
  562.                                      */
  563.                                     DisableBroker( CO_WallStreet );
  564.                                     break;
  565.  
  566.                                 case    CXCMD_ENABLE:
  567.                                     /*
  568.                                      *    Enable the broker.
  569.                                      */
  570.                                     EnableBroker( CO_WallStreet );
  571.                                     break;
  572.  
  573.                                 case    CXCMD_UNIQUE:
  574.                                 case    CXCMD_APPEAR:
  575.                                     /*
  576.                                      *    Open the window.
  577.                                      */
  578.                                     if ( ! WallStreet )
  579.                                         OpenWallStreetWindow();
  580.                                     break;
  581.  
  582.                                 case    CXCMD_DISAPPEAR:
  583.                                     /*
  584.                                      *    Close window.
  585.                                      */
  586.                                     if ( WallStreet )
  587.                                         CloseWallStreetWindow();
  588.                                     break;
  589.  
  590.                                 case    CXCMD_LIST_CHG:
  591.                                     /*
  592.                                      *    Update broker list.
  593.                                      */
  594.                                     BuildBrokerList();
  595.                                     break;
  596.                         }
  597.                         break;
  598.                 }
  599.             }
  600.         }
  601.  
  602.         /*
  603.          *    No. We cannot be stopped by a CTRL-C.
  604.          *
  605.          *    A fearless violation of the C= commodities
  606.          *    programming rules which clearly states:
  607.          *
  608.          *    "The break key for any commodity should be CTRL-C."
  609.          */
  610.  
  611.     } while ( running );
  612. }
  613.  
  614. /*
  615.  *    Setup the program.
  616.  */
  617. static BOOL SetupWallStreet( UBYTE **args )
  618. {
  619.     static UBYTE        *defpopup = "YES", *defpopkey = "control alt help";
  620.     struct Process        *proc = ( struct Process * )FindTask( NULL );
  621.     LONG             priority;
  622.     UBYTE            *popup, *popkey;
  623.  
  624.     /*
  625.      *    Shell?
  626.      */
  627.     if ( proc->pr_CLI ) {
  628.         /*
  629.          *    Obtain startup arguments from the shell.
  630.          */
  631.         if ( ShellArgs = ReadArgs( SHELL, ( LONG * )&Args, NULL )) {
  632.             priority  = sArgInt( Args.Pri,         0           );
  633.             popup      = sArgStr( Args.Popup,     defpopup  );
  634.             popkey      = sArgStr( Args.Popkey,    defpopkey );
  635.             Pubscreen = sArgStr( Args.PubScreen, NULL      );
  636.         } else
  637.             return( FALSE );
  638.     } else {
  639.         /*
  640.          *    Obtain startup arguments from the Workbench.
  641.          */
  642.         TTypes = ( UBYTE ** )ArgArrayInit( NULL, args );
  643.  
  644.         priority  = ArgInt(    TTypes, "CX_PRIORITY",  0         );
  645.         popup      = ArgString( TTypes, "CX_POPUP",     defpopup  );
  646.         popkey      = ArgString( TTypes, "CX_POPKEY",    defpopkey );
  647.         Pubscreen = ArgString( TTypes, "CX_PUBSCREEN", NULL      );
  648.     }
  649.  
  650.     /*
  651.      *    Open BGUI. This program does require version
  652.      *    39 or better of the bgui.library.
  653.      */
  654.     if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  655.         /*
  656.          *    Create the broker.
  657.          */
  658.         CO_WallStreet = CommodityObject,
  659.             COMM_Name,        "Exchange", /* WE MUST HAVE THIS NAME!!! */
  660.             COMM_Title,        VERS " (" DATE ")",
  661.             COMM_Description,    "Another Exchange Clone.",
  662.             COMM_ShowHide,        TRUE,
  663.             COMM_Priority,        priority,
  664.         EndObject;
  665.         /*
  666.          *    OK?
  667.          */
  668.         if ( CO_WallStreet ) {
  669.             /*
  670.              *    Get signal mask.
  671.              */
  672.             GetAttr( COMM_SigMask, CO_WallStreet, &BrokerSig );
  673.             /*
  674.              *    Setup popkey.
  675.              */
  676.             if ( AddHotkey( CO_WallStreet, popkey, CXK_SHOW, 0 )) {
  677.                 /*
  678.                  *    Fire up the broker.
  679.                  */
  680.                 EnableBroker( CO_WallStreet );
  681.                 /*
  682.                  *    Open the window?
  683.                  */
  684.                 if ( ! stricmp( popup, "YES" ))
  685.                     OpenWallStreetWindow();
  686.                 return( TRUE );
  687.             }
  688.             DisposeObject( CO_WallStreet );
  689.         }
  690.         CloseLibrary( BGUIBase );
  691.     }
  692.     return( FALSE );
  693. }
  694.  
  695. /*
  696.  *    Free all resources.
  697.  */
  698. static VOID CloseWallStreet( void )
  699. {
  700.     if ( WO_WallStreet ) DisposeObject( WO_WallStreet );
  701.     if ( CO_WallStreet ) DisposeObject( CO_WallStreet );
  702.     if ( BGUIBase       ) CloseLibrary( BGUIBase );
  703.     if ( TTypes       ) ArgArrayDone();
  704.     if ( ShellArgs       ) FreeArgs( ShellArgs );
  705. }
  706.  
  707. /*
  708.  *    Main entry point. This should work for both
  709.  *    shell and WB startup with SAS (I think).
  710.  */
  711. int main( int argc, char **argv )
  712. {
  713.     if ( SetupWallStreet( argv )) {
  714.         EventHandler();
  715.         CloseWallStreet();
  716.     }
  717.     return( 0 );
  718. }
  719.  
  720. /*
  721.  *    DICE specific workbench startup
  722.  *    entry point.
  723.  */
  724. #ifdef _DCC
  725. int wbmain( struct WBStartup *wbs )
  726. {
  727.     return( main( 0, ( char ** )wbs ));
  728. }
  729. #endif
  730.